package cn.it.xiaohan.note.util;

import com.alibaba.fastjson.JSON;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class JsonUtil {

    public static void toJson(HttpServletResponse response,Object result){

        try {
            // 设置响应的类型
            response.setContentType("application/json;charset=UTF-8");
            // 得到字节输出流
            PrintWriter out = response.getWriter();
            // 将resultInfo转换成Json格式的字符串
            String json = JSON.toJSONString(result);
            // 通过字节输出流输出Json格式的字符串
            out.write(json);
            // 关闭字节输出流
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
